package cn.webrx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Reg6 {
    public static void main(String[] args) {
        String str = """
				<div>hello</div><div>java18 15</div><div><p>java 15</p><span>java 8</p><div>myjava 22html</div></div>
				<div>javascript</div>
				<div>java</div>
				<p>java</p>
				""";

        //Pattern p = Pattern.compile("<div>.*java.*</div>");
        Pattern p = Pattern.compile("<div>[a-zA-Z 0-9]*?java[a-zA-Z 0-9]*?</div>");
        Matcher m = p.matcher(str);
        while(m.find()) {
            System.out.println(m.group());
        }

        //将字符串中的java修改为php
        //将div标签中的java修改为php
        Pattern pp = Pattern.compile("(<div>[a-zA-Z 0-9]*?)(java)([a-zA-Z 0-9]*?</div>)");

        System.out.println("--------------------");
        System.out.println(str);
        System.out.println("--------------------");
        System.out.println(str.replaceAll(pp.toString(),"$1php$3"));
        System.out.println(str.replaceAll("(<div>[a-zA-Z 0-9]*?)(java)([a-zA-Z 0-9]*?</div>)","$1php$3"));

    }
}
